@extends( 'layout.home' )
@section( 'content' )
    <style>
        table.list_tab tr td a {
            margin-right: 0px;
            float: none;
        }
    </style>
<!--面包屑导航 开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="#">首页</a> &raquo; 驶出登记
    <span style="float:right;margin-right: 25px;cursor:pointer;" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</span>
</div>

<!--搜索结果页面 列表 开始-->
<form action="#" method="post">

    <div class="result_wrap">
        <div class="result_content">
            <table class="list_tab">
                <thead>
                <tr>
                    <th class="tc" width="13%">ID</th>
                    <th class="tc" width="13%">车牌号</th>
                    <th class="tc" width="13%">车类型</th>
                    <th class="tc" width="13%">停泊车位</th>
                    <th class="tc" width="13%">月租车</th>
                    <th class="tc" width="22%">进入时间</th>
                    <th class="tc" width="13%">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $v)
                    <tr>
                        <td class="tc">{{$v['id']}}</td>
                        <td class="tc">{{$v['carcity']}} · {{$v['plate_num']}}</td>
                        <td class="tc">
                            @if($v['plate_type']==1)小车
                                @elseif($v['plate_type']==2)客车/货车
                            @endif
                        </td>
                        <td class="tc">NO.{{$v['parkingspace_no']}}</td>
                        <td class="tc">
                            @if($v['is_rent']==1)是
                                @else 否
                            @endif
                        </td>
                        <td class="tc">{{date('Y-m-d H:i:s',$v['drivein_time'])}}</td>
                        <td class="tc">
                            <a href="#"  onclick="pop({{$v['id']}})" javascript:>驶出</a>
                            <a href="#"  onclick="modify({{$v['id']}})" javascript: style="margin-left: 10px;">修改</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

        </div>
    </div>
</form>
    <script src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
<!--搜索结果页面 列表 结束-->
    <script>
        function pop($pid){//弹出框
            layer.open({
                type: 2,
                title:'驶出登记',
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{{url('parking')}}/'+$pid
            });
        }

        function modify($pid){//修改弹出框
            layer.open({
                type: 2,
                title:'修改',
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{{url('parking')}}/'+$pid+'/edit'
            });
        }

        function getdate(time) {//获取时间方法
            var now = new Date(time),
                y = now.getFullYear(),
                m = now.getMonth() + 1,
                d = now.getDate();
            return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
        }

        $("#carcity").bind('change',function(){//监听动作绑定
            var carcity = $(this).val();
            if(!carcity){window.location.reload();}
            $.post("{{url('search')}}",{
                '_token':"{{csrf_token()}}",
                'carcity':carcity,
                'plate_num':''
            },function(data){
                if(data['code']){
                    var h = '';
                    for(var i=0;i<data['msg'].length;i++){
                    h = h + "<tr>";
                    h = h + "<td class=\"tc\">"+ data['msg'][i]['id'] + "</td>";
                    h = h + "<td class=\"tc\">"+ data['msg'][i]['carcity'] + " · "+ data['msg'][i]['plate_num'] + "</td>";
                    h = h + "<td class=\"tc\">"+((data['msg'][i]['plate_type'] == 1)?"小车":"客车/货车")+"</td>";
                    h = h + "<td class=\"tc\">"+getdate(data['msg'][i]['drivein_time']*1000)+"</td>";
                    h = h + "<td class=\"tc\">"+data['msg'][i]['operator']+"</td>";
                    h = h + "<td class=\"tc\">";
                    h = h + "<a href=\"#\"  onclick=\"pop("+ data['msg'][i]['id'] + ")\" javascript:>驶出</a>";
                    h = h + "<a href=\"#\"  onclick=\"modify("+ data['msg'][i]['id'] + ")\" javascript: style=\"margin-left: 10px;\">修改</a>";
                    h = h + "</td>";
                    h = h + "</tr>";
                    }
                    $(".list_tab tbody").html(h);
                }else{
                    $(".list_tab tbody").html("<tr><td class='tc' colspan='7'>"+data.msg+"</td></tr>");
                }
            });
        });

        $("input[name='plate_num']").bind("input propertychange",function(){//搜索动作监听
            var carcity = $("#carcity").val();
            var plate_num = $(this).val();
            if(!plate_num){window.location.reload();}
            $.post("{{url('search')}}",{
                '_token':"{{csrf_token()}}",
                'carcity':carcity,
                'plate_num':plate_num
            },function(data){
                if(data['code']){
                    var h = '';
                    for(var i=0;i<data['msg'].length;i++){
                        h = h + "<tr>";
                        h = h + "<td class=\"tc\">"+ data['msg'][i]['id'] + "</td>";
                        h = h + "<td class=\"tc\">"+ data['msg'][i]['carcity'] + " · "+ data['msg'][i]['plate_num'] + "</td>";
                        h = h + "<td class=\"tc\">"+((data['msg'][i]['plate_type'] == 1)?"小车":"客车/货车")+"</td>";
                        h = h + "<td class=\"tc\">"+getdate(data['msg'][i]['drivein_time']*1000)+"</td>";
                        h = h + "<td class=\"tc\">"+data['msg'][i]['operator']+"</td>";
                        h = h + "<td class=\"tc\">";
                        h = h + "<a href=\"#\"  onclick=\"pop("+ data['msg'][i]['id'] + ")\" javascript:>驶出</a>";
                        h = h + "<a href=\"#\"  onclick=\"modify("+ data['msg'][i]['id'] + ")\" javascript: style=\"margin-left: 10px;\">修改</a>";
                        h = h + "</td>";
                        h = h + "</tr>";
                    }
                    $(".list_tab tbody").html(h);
                }else{
                    $(".list_tab tbody").html("<tr><td class='tc' colspan='7'>"+data.msg+"</td></tr>");
                }
            });
        });
    </script>
@endsection
